package com.tanhua.dubbo.server.vo;

import cn.hutool.core.bean.BeanUtil;
import com.tanhua.dubbo.server.pojo.UserLocation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * * @title: UserLocationVo
 *
 * @Author Philcan
 * @Date: 2021/8/18 15:54
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserLocationVo implements Serializable {
    private Long userId;//用户id
    private String address;//地址
    private Double latitude;//经度
    private Double longitude;//纬度
    private Long created;//创建时间
    private Long updated;//更新时间
    private Long lastUpdated;//上次更新时间

    public static final UserLocationVo format(UserLocation userLocation) {
        UserLocationVo userLocationVo = BeanUtil.toBean(userLocation, UserLocationVo.class);
        userLocationVo.setLongitude(userLocation.getLocation().getLon());
        userLocationVo.setLatitude(userLocation.getLocation().getLat());
        return userLocationVo;
    }

    public static final List<UserLocationVo> formatToList(List<UserLocation> userLocations) {
        List<UserLocationVo> userLocationVoList = new ArrayList<>();
        for (UserLocation userLocation : userLocations) {
            userLocationVoList.add(format(userLocation));
        }
        return userLocationVoList;
    }
}
